﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenTK;
using DDD.Core;
using DDD.OpenTK;
using FloatComparer = DDDTest.Helper.FloatComparer;

namespace DDDTest.OpenTK.TestCapture {
    [TestClass]
    public class TestCapture_RGBA8_ {

        #region Field
        GameWindow window;
        #endregion

        #region Setup
        [TestInitialize ()]
        public void MyClassInitialize () {
            window = new GameWindow ();
        }

        [TestCleanup ()]
        public void MyClassCleanup () {
            window.Dispose ();
            window = null;
        }
        #endregion

        #region TestMethod_R_
        [TestMethod]
        public void Test_Capture_R8_ () {

            var img = new Image2D<float> (PixelFormat.R8, 1, 4);
            var pixels = new float[4] { -1, 0, 1, 4 };
            img.Set (0, 0, 1, 4, pixels);

            img.Compile ();
            img.Capture ();

            var actual = new float[4] { 0, 0, 1, 1 };
            var buf = new float[4];
            img.Get (0, 0, 1, 4, buf);

            CollectionAssert.AreEqual (actual, buf, new FloatComparer(0.01f));
        }

        [TestMethod]
        public void Test_Capture_R8i_ () {

            var img = new Image2D<sbyte> (PixelFormat.R8i, 1, 4);
            var pixels = new sbyte[4] { -1, 0, 1, 2 };
            img.Set (0, 0, 1, 4, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new sbyte[4] { -1, 0, 1, 2 };
            var buf = new sbyte[4];
            img.Get (0, 0, 1, 4, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void Test_Capture_R8ui_ () {

            var img = new Image2D<byte> (PixelFormat.R8ui, 1, 4);
            var pixels = new byte[4] { 0, 1, 2, 3 };
            img.Set (0, 0, 1, 4, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new byte[4] { 0, 1, 2, 3 };
            var buf = new byte[4];
            img.Get (0, 0, 1, 4, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void Test_Capture_R16_ () {

            var img = new Image2D<float> (PixelFormat.R16, 1, 4);
            var pixels = new float[4] { -1, 0, 1, 2 };
            img.Set (0, 0, 1, 4, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new float[4] { 0, 0, 1, 1 };
            var buf = new float[4];
            img.Get (0, 0, 1, 4, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }

        [TestMethod]
        public void Test_Capture_R16f_ () {

            var img = new Image2D<float> (PixelFormat.R16f, 1, 4);
            var pixels = new float[4] { -1, 0, 1, 2 };
            img.Set (0, 0, 1, 4, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new float[4] { -1, 0, 1, 2 };
            var buf = new float[4];
            img.Get (0, 0, 1, 4, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }

        [TestMethod]
        public void Test_Capture_R16i_ () {

            var img = new Image2D<short> (PixelFormat.R16i, 1, 4);
            var pixels = new short[4] { -1, 0, 1, 2 };
            img.Set (0, 0, 1, 4, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new short[4] { -1, 0, 1, 2 };
            var buf = new short[4];
            img.Get (0, 0, 1, 4, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void Test_Capture_R16ui_ () {

            var img = new Image2D<ushort> (PixelFormat.R16ui, 1, 4);
            var pixels = new ushort[4] { 0, 1, 2, 3 };
            img.Set (0, 0, 1, 4, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new ushort[4] { 0, 1, 2, 3 };
            var buf = new ushort[4];
            img.Get (0, 0, 1, 4, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void Test_Capture_R32f_ () {

            var img = new Image2D<float> (PixelFormat.R32f, 1, 4);
            var pixels = new float[4] { -1, 0, 1, 2 };
            img.Set (0, 0, 1, 4, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new float[4] { -1, 0, 1, 2 };
            var buf = new float[4];
            img.Get (0, 0, 1, 4, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }


        [TestMethod]
        public void Test_Capture_RB32i_ () {

            var img = new Image2D<int> (PixelFormat.R32i, 1, 4);
            var pixels = new int[4] { -1, 0, 1, 2 };
            img.Set (0, 0, 1, 4, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new int[4] { -1, 0, 1, 2 };
            var buf = new int[4];
            img.Get (0, 0, 1, 4, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void Test_Capture_RB32ui_ () {

            var img = new Image2D<uint> (PixelFormat.R32ui, 1, 4);
            var pixels = new uint[4] { 0, 1, 2, 3 };
            img.Set (0, 0, 1, 4, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new uint[4] { 0, 1, 2, 3 };
            var buf = new uint[4];
            img.Get (0, 0, 1, 4, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        #endregion

        #region TestMethod_RG_
        [TestMethod]
        public void Test_Capture_RG8_ () {

            var img = new Image2D<float> (PixelFormat.RG8, 1, 2);
            var pixels = new float[4] { -1, 0, 1, 2 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new float[4] { 0, 0, 1, 1 };
            var buf = new float[4];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }

        [TestMethod]
        public void TestCapture_RG8i_ () {

            var img = new Image2D<sbyte> (PixelFormat.RG8i, 1, 2);
            var pixels = new sbyte[4] { -1, 0, 1, 2 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new sbyte[4] { -1, 0, 1, 2 };
            var buf = new sbyte[4];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void TestCapture_RG8ui_ () {

            var img = new Image2D<byte> (PixelFormat.RG8ui, 1, 2);
            var pixels = new byte[4] { 0, 1, 2, 3 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new byte[4] { 0, 1, 2, 3 };
            var buf = new byte[4];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void TestCapture_RG16_ () {

            var img = new Image2D<float> (PixelFormat.RG16, 1, 2);
            var pixels = new float[4] { -1, 0, 1, 2};
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new float[4] { 0, 0, 1, 1 };
            var buf = new float[4];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }

        [TestMethod]
        public void TestCapture_RG16f_ () {

            var img = new Image2D<float> (PixelFormat.RG16f, 1, 2);
            var pixels = new float[4] { -1, 0, 1, 2 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new float[4] { -1, 0, 1, 2 };
            var buf = new float[4];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }

        [TestMethod]
        public void TestCapture_RG16i_ () {

            var img = new Image2D<short> (PixelFormat.RG16i, 1, 2);
            var pixels = new short[4] { -1, 0, 1, 2 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new short[4] { -1, 0, 1, 2 };
            var buf = new short[4];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void TestCapture_RG16ui_ () {

            var img = new Image2D<ushort> (PixelFormat.RG16ui, 1, 2);
            var pixels = new ushort[4] { 0, 1, 2, 3 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new ushort[4] { 0, 1, 2, 3 };
            var buf = new ushort[4];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void TestCapture_RG32f_ () {

            var img = new Image2D<float> (PixelFormat.RG32f, 1, 2);
            var pixels = new float[4] { -1, 0, 1, 2};
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new float[4] { -1, 0, 1, 2 };
            var buf = new float[4];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }


        [TestMethod]
        public void TestCapture_RG32i_ () {

            var img = new Image2D<int> (PixelFormat.RG32i, 1, 2);
            var pixels = new int[4] { -1, 0, 1, 2 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new int[4] { -1, 0, 1, 2 };
            var buf = new int[4];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void TestCapture_RG32ui_ () {

            var img = new Image2D<uint> (PixelFormat.RG32ui, 1, 2);
            var pixels = new uint[4] { 0, 1, 2, 3 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new uint[4] { 0, 1, 2, 3 };
            var buf = new uint[4];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        #endregion

        #region TestMethod_RGB_
        [TestMethod]
        public void Test_Capture_RGB8_ () {

            var img = new Image2D<float> (PixelFormat.RGB8, 1, 2);
            var pixels = new float[6] { -1, 0, 1, 2, 3, 4 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new float[6] { 0, 0, 1, 1, 1, 1 };
            var buf = new float[6];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }

        [TestMethod]
        public void Test_Capture_RGB8i_ () {

            var img = new Image2D<sbyte> (PixelFormat.RGB8i, 1, 2);
            var pixels = new sbyte[6] { -1, 0, 1, 2, 3, 4 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new sbyte[6] { -1, 0, 1, 2, 3, 4 };
            var buf = new sbyte[6];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void Test_Capture_RGB8ui_ () {

            var img = new Image2D<byte> (PixelFormat.RGB8ui, 1, 2);
            var pixels = new byte[6] {0, 1, 2, 3, 4, 5 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new byte[6] { 0, 1, 2, 3, 4, 5 };
            var buf = new byte[6];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void Test_Capture_RGB16_ () {

            var img = new Image2D<float> (PixelFormat.RGB16, 1, 2);
            var pixels = new float[6] { -1, 0, 1, 2, 3, 4  };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new float[6] { 0, 0, 1, 1, 1, 1 };
            var buf = new float[6];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }

        [TestMethod]
        public void Test_Capture_RGB16f_ () {

            var img = new Image2D<float> (PixelFormat.RGB16f, 1, 2);
            var pixels = new float[6] { -1, 0, 1, 2, 3, 4 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new float[6] { -1, 0, 1, 2, 3, 4 };
            var buf = new float[6];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }

        [TestMethod]
        public void Test_Capture_RGB16i_ () {

            var img = new Image2D<short> (PixelFormat.RGB16i, 1, 2);
            var pixels = new short[6] { -1, 0, 1, 2, 3, 4};
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new short[6] { -1, 0, 1, 2, 3, 4 };
            var buf = new short[6];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void Test_Capture_RGB16ui_ () {

            var img = new Image2D<ushort> (PixelFormat.RGB16ui, 1, 2);
            var pixels = new ushort[6] { 0, 1, 2, 3, 4, 5 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new ushort[6] { 0, 1, 2, 3, 4, 5 };
            var buf = new ushort[6];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void Test_Capture_RGB32f_ () {

            var img = new Image2D<float> (PixelFormat.RGB32f, 1, 2);
            var pixels = new float[6] { -1, 0, 1, 2, 3, 4 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new float[6] { -1, 0, 1, 2, 3, 4 };
            var buf = new float[6];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }


        [TestMethod]
        public void Test_Capture_RGB32i_ () {

            var img = new Image2D<int> (PixelFormat.RGB32i, 1, 2);
            var pixels = new int[6] { -1, 0, 1, 2, 3, 4 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new int[6] { -1, 0, 1, 2, 3, 4 };
            var buf = new int[6];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void Test_Capture_RGB32ui_ () {

            var img = new Image2D<uint> (PixelFormat.RGB32ui, 1, 2);
            var pixels = new uint[6] { 0, 1, 2, 3, 4, 5 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new uint[6] { 0, 1, 2, 3, 4, 5 };
            var buf = new uint[6];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        #endregion

        #region TestMethod_RGBA_
        [TestMethod]
        public void Test_Capture_RGBA8 () {

            var img = new Image2D<float> (PixelFormat.RGBA8, 1, 2);
            var pixels = new float[8] { -1, 0, 1, 2, 3, 4, 5, 6 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new float[8] { 0, 0, 1, 1, 1, 1, 1, 1 };
            var buf = new float[8];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }

        [TestMethod]
        public void Test_Capture_RGBA8i_ () {

            var img = new Image2D<sbyte> (PixelFormat.RGBA8i, 1, 2);
            var pixels = new sbyte[8] { -1, 0, 1, 2, 3, 4, 5, 6 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new sbyte[8] { -1, 0, 1, 2, 3, 4, 5, 6 };
            var buf = new sbyte[8];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void Test_Capture_RGBA8ui_ () {

            var img = new Image2D<byte> (PixelFormat.RGBA8ui, 1, 2);
            var pixels = new byte[8] { 0, 1, 2, 3, 4, 5, 6, 7 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new byte[8] { 0, 1, 2, 3, 4, 5, 6, 7 };
            var buf = new byte[8];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void Test_Capture_RGBA16_ () {

            var img = new Image2D<float> (PixelFormat.RGBA16, 1, 2);
            var pixels = new float[8] { -1, 0, 1, 2, 3, 4, 5, 6 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new float[8] { 0, 0, 1, 1, 1, 1, 1, 1 };
            var buf = new float[8];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }

        [TestMethod]
        public void Test_Capture_RGBA16f_ () {

            var img = new Image2D<float> (PixelFormat.RGBA16f, 1, 2);
            var pixels = new float[8] { -1, 0, 1, 2, 3, 4, 5, 6 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new float[8] { -1, 0, 1, 2, 3, 4, 5, 6 };
            var buf = new float[8];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }

        [TestMethod]
        public void Test_Capture_RGBA16i_ () {

            var img = new Image2D<short> (PixelFormat.RGBA16i, 1, 2);
            var pixels = new short[8] { -1, 0, 1, 2, 3, 4, 5, 6 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new short[8] { -1, 0, 1, 2, 3, 4, 5, 6 };
            var buf = new short[8];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void Test_Capture_RGBA16ui_ () {

            var img = new Image2D<ushort> (PixelFormat.RGBA16ui, 1, 2);
            var pixels = new ushort[8] { 0, 1, 2, 3, 4, 5, 6, 7 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new ushort[8] { 0, 1, 2, 3, 4, 5, 6, 7 };
            var buf = new ushort[8];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void Test_Capture_RGBA32f_ () {

            var img = new Image2D<float> (PixelFormat.RGBA32f, 1, 2);
            var pixels = new float[8] { -1, 0, 1, 2, 3, 4, 5, 6 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new float[8] { -1, 0, 1, 2, 3, 4, 5, 6 };
            var buf = new float[8];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }


        [TestMethod]
        public void Test_Capture_RGBA32i_ () {

            var img = new Image2D<int> (PixelFormat.RGBA32i, 1, 2);
            var pixels = new int[8] { -1, 0, 1, 2, 3, 4, 5, 6 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new int[8] { -1, 0, 1, 2, 3, 4, 5, 6 };
            var buf = new int[8];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void Test_Capture_RGBA32ui_ () {

            var img = new Image2D<uint> (PixelFormat.RGBA32ui, 1, 2);
            var pixels = new uint[8] { 0, 1, 2, 3, 4, 5, 6, 7 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            var expected = new uint[8] { 0, 1, 2, 3, 4, 5, 6, 7 };
            var buf = new uint[8];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        #endregion

        #region TestMethod_Others
        [TestMethod]
        public void Test_Capture_RGB9e5_ () {

            var img = new Image2D<float> (PixelFormat.RGB9e5, 1, 2);
            var pixels = new float[6] { -1, 0, 1, 2, 3, 4 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            Console.WriteLine (img.Cpp);

            var expected = new float[6] { 0, 0, 1, 2, 3, 4 };
            var buf = new float[6];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }

        [TestMethod]
        public void Test_Capture_R11G11B10f_ () {

            var img = new Image2D<float> (PixelFormat.R11G11B10f, 1, 2);
            var pixels = new float[6] { -1, 0, 1, 2, 3, 4 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            Console.WriteLine (img.Cpp);

            var expected = new float[6] { 0, 0, 1, 2, 3, 4 };
            var buf = new float[6];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }

        [TestMethod]
        public void Test_Capture_RGB10A2_ () {

            var img = new Image2D<float> (PixelFormat.RGB10A2, 1, 2);
            var pixels = new float[8] { -1, 0, 1, 2, 3, 4, 5, 6 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            Console.WriteLine (img.Cpp);

            var expected = new float[8] { 0, 0, 1, 1, 1, 1, 1, 1 };
            var buf = new float[8];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }

        [TestMethod]
        public void Test_Capture_RGB10A2ui_ () {

            var img = new Image2D<ushort> (PixelFormat.RGB10A2ui, 1, 2);
            var pixels = new ushort[8] { 0, 1, 2, 3, 4, 5, 6, 7 };
            img.Set (0, 0, 1, 2, pixels);

            img.Compile ();
            img.Capture ();

            Console.WriteLine (img.Cpp);

            // Aは2bitなので最大3
            var expected = new ushort[8] { 0, 1, 2, 3, 4, 5, 6, 3 };
            var buf = new ushort[8];
            img.Get (0, 0, 1, 2, buf);

            CollectionAssert.AreEqual (expected, buf);
        }

        [TestMethod]
        public void Test_Capture_Depth_ () {

            var img = new Image2D<float> (PixelFormat.Depth, 1, 4);
            var pixels = new float[4] { -1, 0, 1, 2 };
            img.Set (0, 0, 1, 4, pixels);

            img.Compile ();
            img.Capture ();

            Console.WriteLine (img.Cpp);

            var expected = new float[4] { 0, 0, 1, 1 };
            var buf = new float[4];
            img.Get (0, 0, 1, 4, buf);

            CollectionAssert.AreEqual (expected, buf, new FloatComparer(0.01f));
        }
        #endregion
    }
}
